package cn.dd.crmweb.modules.discern.emotion.controller;


import cn.dd.crmweb.common.Result;
import cn.dd.crmweb.modules.discern.emotion.entity.AudioEmDc;
import cn.dd.crmweb.modules.discern.emotion.mapper.AudioEmDcMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tbb
 * @since 2023-05-01
 */
@RestController
@RequestMapping("/audio/emotion")
public class AudioEmDcController {
    @Autowired
    private AudioEmDcMapper audioEmDcMapper;

    @GetMapping("/list")
    public Result findAll(){
//        audioEmDcMapper.selectList(null);
        return Result.success(audioEmDcMapper.selectList(null));
    }

    @PostMapping("/upload")
    public Result uploadFile(@RequestParam("file") MultipartFile file){
        LocalDateTime time = LocalDateTime.now();
//        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//        DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        AudioEmDc audioEmDc = new AudioEmDc();
        audioEmDc.setFileName(file.getOriginalFilename());
        audioEmDc.setFileType(file.getContentType());
        audioEmDc.setCreateTime(time);
        audioEmDcMapper.insert(audioEmDc);
        System.out.println(file.getOriginalFilename());
//        audioEmDcMapper.selectList(null);
        return Result.success();
    }
}

